package com.shungen.apicloud.utils;

import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;

public class EmailValidator {

    public static boolean isValidEmail(String email) {
        boolean isValid = true;
        try {
            InternetAddress emailAddr = new InternetAddress(email);
            emailAddr.validate();
        } catch (AddressException ex) {
            isValid = false;
        }
        return isValid;
    }

    public static void main(String[] args) {
        // 测试示例
        String[] testEmails = {
                "test@example.com",
                "invalid-email",
                "user.name+tag+sorting@example.com",
                "user@sub.example.com",
                "user@.com",
                "user@com"
        };

        for (String email : testEmails) {
            System.out.println("Is " + email + " a valid email? " + isValidEmail(email));
        }
    }
}
